package org.hmh.offer;

/**
 * Created this one by HMH on 2018/1/19.
 */
public class t6 {
    public static class Solution {
        public int minNumberInRotateArray(int[] array) {
            int left = 0, right = array.length - 1;
            while (left < right) {
                int mid = left + (right - left) / 2;
                if (array[left] < array[mid] && array[mid] > array[right]) {
                    left = mid ;
                } else if (array[left] > array[mid] && array[mid] < array[right]) {
                    right = mid ;
                } else {
                    return find(left, right, array);
                }
            }
            return array[left];
        }

        public int find(int left, int right, int[] arr) {
            int min = Integer.MAX_VALUE;
            for (int i = left; i <= right; i++) {
                if (min > arr[i]) {
                    min = arr[i];
                }
            }
            return min;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int min = solution.minNumberInRotateArray(new int[]{6501, 6828, 6963, 7036, 7422, 7674, 8146, 8468, 8704, 8717, 9170, 9359, 9719, 9895, 9896, 9913, 9962, 154, 293, 334, 492, 1323, 1479, 1539, 1727, 1870, 1943, 2383, 2392, 2996, 3282, 3812, 3903, 4465, 4605, 4665, 4772, 4828, 5142, 5437, 5448, 5668, 5706, 5725, 6300, 6335});
        System.out.println(min);
    }
}
